/*     */ package com.wgcloud.util;
/*     */ 
/*     */ import java.io.File;
/*     */ import java.io.FileInputStream;
/*     */ import java.io.IOException;
/*     */ import java.security.MessageDigest;
/*     */ import java.security.NoSuchAlgorithmException;
/*     */ import org.apache.commons.lang3.StringUtils;
/*     */ import org.slf4j.Logger;
/*     */ import org.slf4j.LoggerFactory;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class MD5Utils
/*     */ {
/*  23 */   private static final Logger logger = LoggerFactory.getLogger(com.wgcloud.util.MD5Utils.class);
/*     */ 
/*     */   
/*  26 */   private static final String[] strDigits = new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*  32 */   private static final char[] hexdigits = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static String getMD5ForFile(String filePath) {
/*  43 */     FileInputStream fis = null;
/*  44 */     MessageDigest md = null;
/*     */     try {
/*  46 */       md = MessageDigest.getInstance("MD5");
/*  47 */       File file = new File(filePath);
/*  48 */       if (!file.exists()) {
/*  49 */         return "";
/*     */       }
/*  51 */       fis = new FileInputStream(file);
/*  52 */       byte[] buffer = new byte[4096];
/*  53 */       int length = -1;
/*  54 */       while ((length = fis.read(buffer)) != -1) {
/*  55 */         md.update(buffer, 0, length);
/*     */       }
/*  57 */       byte[] b = md.digest();
/*  58 */       return byteToHexString(b);
/*  59 */     } catch (Exception ex) {
/*  60 */       logger.error("获取MD5信息发生异常！" + ex.toString());
/*  61 */       return null;
/*     */     } finally {
/*     */       try {
/*  64 */         if (null != fis) {
/*  65 */           fis.close();
/*     */         }
/*  67 */       } catch (IOException e) {
/*  68 */         logger.error("获取MD5信息发生异常！" + e.toString());
/*     */       } 
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private static String byteToHexString(byte[] tmp) {
/*  81 */     char[] str = new char[32];
/*  82 */     int k = 0;
/*  83 */     for (int i = 0; i < 16; i++) {
/*  84 */       byte byte0 = tmp[i];
/*  85 */       str[k++] = hexdigits[byte0 >>> 4 & 0xF];
/*  86 */       str[k++] = hexdigits[byte0 & 0xF];
/*     */     } 
/*  88 */     String s = new String(str);
/*  89 */     return s;
/*     */   }
/*     */ 
/*     */   
/*     */   private static String byteToArrayString(byte bByte) {
/*  94 */     int iRet = bByte;
/*     */     
/*  96 */     if (iRet < 0) {
/*  97 */       iRet += 256;
/*     */     }
/*  99 */     int iD1 = iRet / 16;
/* 100 */     int iD2 = iRet % 16;
/* 101 */     return strDigits[iD1] + strDigits[iD2];
/*     */   }
/*     */ 
/*     */   
/*     */   private static String byteToNum(byte bByte) {
/* 106 */     int iRet = bByte;
/* 107 */     System.out.println("iRet1=" + iRet);
/* 108 */     if (iRet < 0) {
/* 109 */       iRet += 256;
/*     */     }
/* 111 */     return String.valueOf(iRet);
/*     */   }
/*     */ 
/*     */   
/*     */   private static String byteToString(byte[] bByte) {
/* 116 */     StringBuffer sBuffer = new StringBuffer();
/* 117 */     for (int i = 0; i < bByte.length; i++) {
/* 118 */       sBuffer.append(byteToArrayString(bByte[i]));
/*     */     }
/* 120 */     return sBuffer.toString();
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static String GetMD5Code(String strObj) {
/* 129 */     if (StringUtils.isEmpty(strObj)) {
/* 130 */       return "";
/*     */     }
/* 132 */     String resultString = null;
/*     */     try {
/* 134 */       resultString = new String(strObj);
/* 135 */       MessageDigest md = MessageDigest.getInstance("MD5");
/*     */       
/* 137 */       resultString = byteToString(md.digest(strObj.getBytes()));
/* 138 */     } catch (NoSuchAlgorithmException ex) {
/* 139 */       ex.printStackTrace();
/*     */     } 
/* 141 */     return resultString;
/*     */   }
/*     */ }


/* Location:              /Users/zhangyongxin/soft-install/wgcloud/wgcloud-v3.3.5/server/bank/wgcloud-server-release.jar!/BOOT-INF/classes/com/wgcloud/util/MD5Utils.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */